<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>9.阻止事件冒泡</title>
    <style>
        .box {
            width: 400px;
            height: 400px;
            background-color: aqua;
        }

        .box1 {
            width: 100px;
            height: 100px;
            background-color: rgb(255, 0, 38);
        }

        .box2 {
            width: 100px;
            height: 100px;
            background-color: rgb(204, 255, 0);
        }
    </style>
</head>

<body>
    <div class="box">
        bodafasefea
        <div class="box1">box1</div>
        <div class="box2">box2</div>
    </div>
</body>
<script>
    var box = document.getElementsByClassName('box')[0]
    var box1 = document.getElementsByClassName('box1')[0]
    var box2 = document.getElementsByClassName('box2')[0]
    //第三个参数为true时候，在捕获阶段就会执行,不用经过冒泡阶段
    //所以阻止冒泡不会对true的元素造成影响
    box.addEventListener('click', function (e) {
        console.log('点击父元素box')
    }, true)
    box1.addEventListener('click', function (e) {
        console.log('点击zi元素box1')
    })
    box2.addEventListener('click', function (e) {
        console.log('点击zi元素box2')
        //阻止元素冒泡
        e.stopPropagation()
    })

</script>

</html>